﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class roleControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        MPRepeater MPRepeaterList;
        TextBox rolname;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            //if (!base.Page.IsPostBack) {
                Bind();
            //}
            Button rolnamebtn = (Button)FindControl("rolnamebtn");
            rolnamebtn.Click += new EventHandler(rolnamebtn_Click);
        }
        protected void InitControl() {
            MPRepeaterList = (MPRepeater)FindControl("MPRepeaterList");
            rolname = (TextBox)FindControl("rolname");
        }
        protected void rolnamebtn_Click(object sender, EventArgs e)
        {
            Bind();
        }
        protected void Bind()
        {
            string strwhere = "";
            if (!string.IsNullOrEmpty(rolname.Text)) { strwhere = " and ROLENAME like '%" + rolname.Text + "%' "; }
            DataTable dt = _EluZSDataProvider.GetROLE(strwhere);
            MPRepeaterList.DataSource = dt;
            MPRepeaterList.DataBind();
        }
        /// <summary>
        /// 省略字符
        /// </summary>
        /// <returns></returns>
        public static string TranString(object str, int length)
        {
            if (str != null)
            {
                if (!string.IsNullOrEmpty(str.ToString()))
                {
                    if (str.ToString().Length > length)
                    {
                        return "<span title='" + str.ToString() + "'>" + str.ToString().Substring(0, length) + "..." + "</span>";
                    }
                    return str.ToString();
                }
            }
            return "";
        }
    }
}


